package com.tiantian.util;

import java.io.UnsupportedEncodingException;

import org.apache.commons.lang3.StringUtils;

public class StringDBUtils {
	/**
	 * 转换为Latin1格式
	 * 
	 * @param str
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String toLatin1DbString(String str) throws UnsupportedEncodingException {
		if (StringUtils.isNotBlank(str)) {
			return new String(str.getBytes("UTF-8"), "ISO-8859-1");
		}
		return null;
	}

	/**
	 * 转换为utf8格式
	 * 
	 * @param str
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	public static String toUtf8String(String str) throws UnsupportedEncodingException {
		if (StringUtils.isNotBlank(str)) {
			return new String(str.getBytes("ISO-8859-1"), "UTF-8");
		}
		return null;
	}
}
